package com.xyrl.project.common.base.vo;

import io.swagger.annotations.ApiModel;

/**
 *  * @className ResponseData
 *  * @company 星纭融链科技服务有限公司
 *  * @author 徐恩源
 *  * @version 1.0
 *  * @date 2019-12-30 10:03:06
 *  * @Description 返回对象
 *  
 */
@ApiModel
public class ResponseData<T> {
    //成功
    public static final int STATUS_OK = 0;
    //失败
    public static final int STATUS_ERROR = -1;
    //其他地方登录
    public static final int OTHER_LOGIN = 1;
    /**
     * 状态：0
     */
    private int status;
    /**
     * 消息
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;

    public ResponseData() {
    }

    //处理成功的方法
    public static ResponseData success(Object result) {
        return ResponseData.build(result, "success", STATUS_OK);
    }

    //处理成功的方法
    public static ResponseData success() {
        return ResponseData.build("", "success", STATUS_OK);
    }

    //处理错误的方法
    public static ResponseData error(String message) {
        return ResponseData.build(null, message, STATUS_ERROR);
    }

    //处理错误的方法
    public static ResponseData otherLogin(String message) {
        return ResponseData.build(null, message, OTHER_LOGIN);
    }

    public static ResponseData build(Object result, String message, int status) {
        ResponseData type = new ResponseData();
        type.setData(result);
        type.setStatus(status);
        type.setMessage(message);
        return type;
    }

    public int getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResponseData(String message) {
        this.message = message;
    }
}
